package ms.unicorn.reasoning;

import java.util.Collection;

import ms.unicorn.Element;
import ms.unicorn.dsl.analysis.impl.AbstractAnalysis;

public class MaxBeliefAnalysis extends AbstractAnalysis {

	private FDGraph graph;
	private DAT alternatives;

	public MaxBeliefAnalysis(Element rootElement) {
		super(rootElement);
	}

	@Override
	public String getName() {
		return "Evolution Analysis";
	}

	@Override
	public String getConversionScheme() {
		return "FDGraph";
	}
	
	@Override
	public void runAnalysis() {
		clearCache();
		this.graph = convert();
		if (graph != null) {
			System.out.println(graph.getDummyRoot().toString());
			graph.propagateDAT();
			this.alternatives = graph.getDummyRoot().getDAT().consolidate();
		}
		else this.alternatives = null;
		super.runAnalysis();
	}
	
	public Collection<AnnotatedAlternative> getAlternatives() {
		return alternatives;	
	}

	public DAT getDAT(Element e) {
		if (e == null)
			return null;
		Object o = getConvertedObject(e.getId());
		if (o instanceof FDNode)
			return ((FDNode) o).getDAT();
		else if ( graph != null && graph.getDummyRoot() != null)
			return graph.getDummyRoot().getDAT();
		return null;
	}
	
}
